package com.leoandroid.tool.toolsbox.largeread.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.leoandroid.tool.toolsbox.largeread.activity.MultiLightActivity;
import com.leoandroid.tool.toolsbox.largeread.activity.ScreenLightActivity;
import com.leoandroid.tool.toolsbox.largeread.R;
import com.leoandroid.tool.toolsbox.largeread.activity.AlarmLightActivity;
import com.leoandroid.tool.toolsbox.largeread.activity.EatActivity;
import com.leoandroid.tool.toolsbox.largeread.activity.FlashLightActivity;
import com.leoandroid.tool.toolsbox.largeread.activity.WarningLightActivity;
import com.leoandroid.tool.toolsbox.largeread.utils.FlashlightUtils;

public class MultiFunctionFragment extends Fragment {

    private View v;
    private LinearLayout layoutSos;
    private LinearLayout layoutFlashLamp;
    private LinearLayout layoutAlarmLamp;
    private LinearLayout layoutScreenLamp;
    private LinearLayout layoutIllumination;
    private LinearLayout layoutCautionLamp;
    private LinearLayout jiaotongLl;
    private LinearLayout jieqiLl;
    private ImageView imgSos;
    private TextView tvSos;

    private boolean isSosOpen = false;

    public static MultiFunctionFragment getInstance(){
        return new MultiFunctionFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        v = inflater.inflate(R.layout.fragment_classify,container,false);
        initView();
        return v;
    }

    private void initView(){
        layoutSos = v.findViewById(R.id.sos_layout);
        imgSos = v.findViewById(R.id.sos_img);
        tvSos = v.findViewById(R.id.sos_tv);
        layoutFlashLamp = v.findViewById(R.id.flash_lamp_layout);
        layoutAlarmLamp = v.findViewById(R.id.alarm_lamp_layout);
        layoutScreenLamp = v.findViewById(R.id.screen_lamp_layout);
        layoutIllumination = v.findViewById(R.id.illumination_layout);
        layoutCautionLamp = v.findViewById(R.id.caution_lamp_layout);
        jiaotongLl = v.findViewById(R.id.jiaotong_layout);
        jieqiLl = v.findViewById(R.id.jieqi_layout);

        layoutSos.setOnClickListener(view -> {
            if(!isSosOpen){
                layoutSos.setBackgroundResource(R.drawable.bg_black_10dp);
                imgSos.setImageResource(R.mipmap.ic_multifunction_sos_on);
                tvSos.setTextColor(getResources().getColor(R.color.color_f3f3f3));
                FlashlightUtils.sos(5);
                isSosOpen = true;
            }else{
                layoutSos.setBackgroundResource(R.drawable.bg_white_10dp);
                imgSos.setImageResource(R.mipmap.ic_multifunction_sos_default);
                tvSos.setTextColor(getResources().getColor(R.color.color_333333));
                FlashlightUtils.offSos();
                isSosOpen = false;
            }
        });

        layoutFlashLamp.setOnClickListener(view -> {
            Intent intent = new Intent(getActivity(), FlashLightActivity.class);
            startActivity(intent);
        });

        layoutAlarmLamp.setOnClickListener(view -> {
            Intent intent = new Intent(getActivity(), AlarmLightActivity.class);
            startActivity(intent);
        });

        layoutScreenLamp.setOnClickListener(view -> {
            Intent intent = new Intent(getActivity(), ScreenLightActivity.class);
            startActivity(intent);
        });

        layoutIllumination.setOnClickListener(view -> {
            Intent intent = new Intent(getActivity(), MultiLightActivity.class);
            startActivity(intent);
        });

        layoutCautionLamp.setOnClickListener(view -> {
            Intent intent = new Intent(getActivity(), WarningLightActivity.class);
            startActivity(intent);
        });

        jiaotongLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), EatActivity.class);
                intent.putExtra("KEY","file:///android_asset/game/jiaotongbiaozhi/index.html");
                getActivity().startActivity(intent);
            }
        });
        jieqiLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), EatActivity.class);
                intent.putExtra("KEY","file:///android_asset/game/ershisijieqi/index.html");
                getActivity().startActivity(intent);
            }
        });
    }
}
